package common.service.impl.jedis;

//Redis 连接测试
//import org.junit.Test;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import common.service.JedisClient;

import java.util.*;

public class JedisClientTest {
   
	@Test
	public void testJedisClient() throws Exception{
	   
	    //初始化Spring容器
//		ApplicationContext applicationContext=new ClassPathXmlApplicationContext("classpath:applicationContext-redis.xml");
//		JedisClient jedisClient=applicationContext.getBean(JedisClient.class);

		List<Map<String,Object>> params=new ArrayList<>();
		Map<String,Object> map1=new HashMap<>();
		map1.put("host","192.168.6.98");
		map1.put("port","5201");
		Map<String,Object> map2=new HashMap<>();
		map2.put("host","192.168.6.98");
		map2.put("port","5202");
		Map<String,Object> map3=new HashMap<>();
		map3.put("host","192.168.6.98");
		map3.put("port","5203");
		Map<String,Object> map4=new HashMap<>();
		map4.put("host","192.168.6.98");
		map4.put("port","5204");
		Map<String,Object> map5=new HashMap<>();
		map5.put("host","192.168.6.98");
		map5.put("port","5205");
		Map<String,Object> map6=new HashMap<>();
		map6.put("host","192.168.6.98");
		map6.put("port","5206");
		params.add(map1);
		params.add(map2);
		params.add(map3);
		params.add(map4);
		params.add(map5);
		params.add(map6);


		Set<HostAndPort> nodes=new HashSet<>();
		for (Map<String,Object> map:params) {
			nodes.add(new HostAndPort(map.get("host").toString(), Integer.parseInt(map.get("port").toString())));
		}

		//集群
		JedisClientCluster jedisClientCluster=new JedisClientCluster();
		                   jedisClientCluster.jedisCluster=new JedisCluster(nodes,5000,1000,5000,"52yst",new GenericObjectPoolConfig());

		jedisClientCluster.set("ystinfo","2");
		System.out.println(jedisClientCluster.get("ystinfo"));

		//单机
//		JedisClientPool jedisClientCluster=new JedisClientPool();
//		jedisClientCluster.jedisPool=new JedisPool(new GenericObjectPoolConfig(),params.get(0).get("host").toString(),Integer.parseInt(params.get(0).get("port").toString()),3000,"52yst");
//
//		jedisClientCluster.set("ystinfo","2");
//		System.out.println(jedisClientCluster.get("ystinfo"));
   }


}
